package com.teamin.web.bind;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.beans.PropertyEditorSupport;
import java.util.Date;

/**
* 扩展类型转换
*/
public class CustomDateEditor extends PropertyEditorSupport {
	private Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
     */
    @Override
    public void setAsText(String text){
    	try {
    		logger.info("时间转换 setAsText" + text);
        	Long l = Long.decode(text);
            setValue(new Date(l));
		} catch (Exception e) {
			setValue(null);
		}
    	
    }

    /**
     * @see java.beans.PropertyEditorSupport#getAsText()
     */
//    @Override
//    public String getAsText() {
//        Date value = (Date) getValue();
//        String returnValue = (value != null ? String.valueOf(TimeUnit.MILLISECONDS.toSeconds(value.getTime())) : "");
//        logger.info("时间转换 getAsText" + returnValue);
//        return returnValue;
//    }

}